package com.ryan.ohos.extension.util;

import ohos.agp.components.Image;
import ohos.agp.components.element.Element;
import ohos.agp.render.BlendMode;
import ohos.agp.utils.Color;

public class ImageTint {


    public static Element getTintElement(Element element, String colorStr) {
        int intColor = Color.getIntColor(colorStr);
        return getTintElement(element, intColor);
    }

    public static Element getTintElement(Element element, int intColor) {

        return getTintElement(element, intColor, BlendMode.SRC_ATOP);
    }

    public static Element getTintElement(Element element, int intColor, BlendMode mode) {
        int[] colors = new int[]{intColor, intColor};
        int[][] states = new int[2][];
        states[0] = new int[]{0};
        states[1] = new int[]{0};
        element.setStateColorList(states, colors);
        element.setStateColorMode(mode);
        return element;
    }

    public static void setImageTint(Image view, Element element, String colorStr) {
        getTintElement(element, colorStr);
        setImageElement(view, element);
    }

    public static void setImageTint(Image view, Element element, int intColor) {
        getTintElement(element, intColor);
        setImageElement(view, element);
    }

    public static void setImageTint(Image view, Element element, int intColor, BlendMode mode) {
        getTintElement(element, intColor, mode);
        setImageElement(view, element);
    }

    public static void setImageElement(Image view, Element element) {
        view.setImageElement(element);
    }
}
